package com.st.service.serviceImpl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.st.dao.GoodsDetailMapper;
import com.st.po.GoodsSelectLikePo;
import com.st.pojo.GoodsDetail;
import com.st.vo.GetGoodsVo;
import com.st.vo.GoodsConditionsVo;
import com.st.vo.GoodsSelectLikeVo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.ArrayList;
import java.util.List;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import java.util.List;
import com.st.dao.GoodsMapper;
import com.st.pojo.Goods;
import com.st.service.GoodsService;
@Service
public class GoodsServiceImpl extends ServiceImpl<GoodsMapper, Goods> implements GoodsService{

    @Resource
    private GoodsMapper goodsMapper;

    @Resource
    private GoodsDetailMapper goodsDetailMapper;

    @Override
    public int batchInsert(List<Goods> list) {
        return baseMapper.batchInsert(list);
    }

    @Override
    public List<GoodsSelectLikeVo> getList(GoodsSelectLikePo goodsSelectLikePo) {
        QueryWrapper<Goods> qw = new QueryWrapper<>();
        qw.like(Goods.COL_NAME,goodsSelectLikePo.getName());
        qw.orderByDesc(Goods.COL_SALE);
        List<GoodsSelectLikeVo> goodsSelectLikeVoList  = new ArrayList<>();
        List<Goods> goods = goodsMapper.selectList(qw);
        for (Goods good : goods) {
            GoodsSelectLikeVo goodsSelectLikeVo = new GoodsSelectLikeVo(good.getName(),good.getPrice(),good.getFlowerLanguage());
            goodsSelectLikeVoList.add(goodsSelectLikeVo);
        }
        return goodsSelectLikeVoList;
    }


    @Override
    public List<GoodsConditionsVo> getConditionsList(Integer detailId, Integer sale, Integer price, Integer createTime, String standard) {

        List<GoodsConditionsVo> goodsConditionsVos = new ArrayList<>();
        if (standard==null) {
            List<Goods> goodsList = goodsMapper.getConditionsList(detailId, sale, price,createTime);
            for (Goods goods : goodsList) {
                GoodsConditionsVo goodsConditionsVo = new GoodsConditionsVo(goods.getName(),goods.getPrice(),goods.getFlowerLanguage());
                goodsConditionsVos.add(goodsConditionsVo);
            }
            return goodsConditionsVos;
        }
        QueryWrapper<GoodsDetail> qw = new QueryWrapper();
        qw.eq(GoodsDetail.COL_NAME,standard);
        GoodsDetail goodsDetail = goodsDetailMapper.selectOne(qw);
        qw.clear();
        QueryWrapper<Goods> qw1 = new QueryWrapper<>();
        qw1.eq(Goods.COL_CATEGORIZE_ID,goodsDetail.getId());
        List<Goods> goodsList = goodsMapper.selectList(qw1);
        qw1.clear();
        for (Goods goods : goodsList) {
            GoodsConditionsVo goodsConditionsVo = new GoodsConditionsVo(goods.getName(),goods.getPrice(),goods.getFlowerLanguage());
            goodsConditionsVos.add(goodsConditionsVo);
        }
        return goodsConditionsVos;
    }

    @Override
    public GetGoodsVo getGoods(Integer id) {
        QueryWrapper<Goods> qw = new QueryWrapper<>();
        qw.eq(Goods.COL_ID,id);
        Goods goods = goodsMapper.selectOne(qw);
        qw.clear();
        GetGoodsVo getGoodsVo = new GetGoodsVo(goods.getName(),goods.getPrice(),goods.getArticleNumber(),goods.getMaterial(),goods.getPackages(),goods.getFlowerLanguage(),goods.getBundled(),goods.getDelivery(),goods.getContentFlag());

        return getGoodsVo;
    }
}
